package cn.lijian.goods.book.service;

import java.sql.SQLException;

import cn.lijian.goods.book.dao.BookDao;
import cn.lijian.goods.book.domain.Book;
import cn.lijian.goods.pager.PageBean;

public class BookService {

	private BookDao bookDao=new BookDao();
	
	public void delete(String bid){
		try {
			bookDao.delete(bid); 
		} catch (SQLException e) {
			throw new RuntimeException(e);
		}
	}
	
	/**
	 * 修改图书
	 * @param book
	 * @author lijian
	 */
	public void edit(Book book){
		try {
			bookDao.edit(book);
		} catch (SQLException e) {
			throw new RuntimeException(e);
		}
	}
	
	/**
	 * 返回当前分类下图书个数
	 * @param cid
	 * @return
	 * @author lijian
	 */
	public int findBookCountByCategory(String cid){
		try {
			return bookDao.findBookByCategory(cid);
		} catch (SQLException e) {
			throw new RuntimeException(e);
		}
	}
	/**
	 * 加载图书
	 * 	点击某本书时调用这里
	 * @param bid
	 * @return
	 * @author lijian
	 */
	public Book load(String bid){
		try {
			return bookDao.findByBid(bid);
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			throw new RuntimeException(e);
		}
	}
	/**
	 * 按分类查询
	 * @param cid
	 * @param pc
	 * @return
	 * @author lijian
	 */
	public PageBean<Book>findByCategory(String cid,int pc){
		try {
			return bookDao.findByCategory(cid, pc);
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			throw new RuntimeException(e);
		}
	}
	
	/**
	 * 按书名模糊查询
	 * @param cid
	 * @param pc
	 * @return
	 * @author lijian
	 */
	public PageBean<Book>findByBname(String bname,int pc){
		try {
			return bookDao.findByBname(bname, pc);
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			throw new RuntimeException(e);
		}
	}
	
	/**
	 * 按作者查询
	 * @param cid
	 * @param pc
	 * @return
	 * @author lijian
	 */
	public PageBean<Book>findByAuthor(String author,int pc){
		try {
			return bookDao.findByAuthor(author, pc);
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			throw new RuntimeException(e);
		}
	}
	
	/**
	 * 组合查询
	 * @param cid
	 * @param pc
	 * @return
	 * @author lijian
	 */
	public PageBean<Book>findByCombination(Book book,int pc){
		try {
			return bookDao.findByCombination(book, pc);
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			throw new RuntimeException(e);
		}
	}
	
	/**
	 * 按出版社查询
	 * @param cid
	 * @param pc
	 * @return
	 * @author lijian
	 */
	public PageBean<Book>findByPress(String press,int pc){
		try {
			return bookDao.findByPress(press, pc);
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			throw new RuntimeException(e);
		}
	}
	/**
	 * 添加图书
	 * 
	 * @author lijian
	 */
	public void add(Book book) {
		// TODO Auto-generated method stub
		try {
			bookDao.add(book);
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			throw new RuntimeException(e);
		}
	}
	
}
